package com.ruoyi.bizsys.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bizsys.domain.FaqQuestion;
import com.ruoyi.bizsys.service.IFaqQuestionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 常见问题Controller
 *
 * @author african-loan
 * @date 2021-04-21
 */
@RestController
@RequestMapping("/business/faq_question")
public class FaqQuestionController extends BaseController {
    @Autowired
    private IFaqQuestionService faqQuestionService;

/**
 * 查询常见问题列表
 */
@PreAuthorize("@ss.hasPermi('business:faq_question:list')")
@GetMapping("/list")
        public TableDataInfo list(FaqQuestion faqQuestion) {
        startPage();
        List<FaqQuestion> list = faqQuestionService.selectFaqQuestionList(faqQuestion);
        return getDataTable(list);
    }
    
    /**
     * 导出常见问题列表
     */
    @PreAuthorize("@ss.hasPermi('business:faq_question:export')")
    @Log(title = "常见问题", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FaqQuestion faqQuestion) {
        List<FaqQuestion> list = faqQuestionService.selectFaqQuestionList(faqQuestion);
        ExcelUtil<FaqQuestion> util = new ExcelUtil<FaqQuestion>(FaqQuestion.class);
        return util.exportExcel(list, "faq_question");
    }

    /**
     * 获取常见问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:faq_question:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(faqQuestionService.selectFaqQuestionById(id));
    }

    /**
     * 新增常见问题
     */
    @PreAuthorize("@ss.hasPermi('business:faq_question:add')")
    @Log(title = "常见问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaqQuestion faqQuestion) {
        return toAjax(faqQuestionService.insertFaqQuestion(faqQuestion));
    }

    /**
     * 修改常见问题
     */
    @PreAuthorize("@ss.hasPermi('business:faq_question:edit')")
    @Log(title = "常见问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaqQuestion faqQuestion) {
        return toAjax(faqQuestionService.updateFaqQuestion(faqQuestion));
    }

    /**
     * 删除常见问题
     */
    @PreAuthorize("@ss.hasPermi('business:faq_question:remove')")
    @Log(title = "常见问题", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(faqQuestionService.deleteFaqQuestionByIds(ids));
    }
}
